package Vistas;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class FrmCambio extends javax.swing.JFrame {
	private JLabel LblTotal;
	private JTextField TxtTotal;
	private JTextField txtCambio;
	private JButton BtnCalcular;
	private JLabel lblCambio;
	private JTextField txtPaga;
	private JLabel LblPago;

	/**
	* Auto-generated main method to display this JFrame
	*/
	
	
	public FrmCambio() {
		super();
		initGUI();
		TxtTotal.setEnabled(false);
	}
	
	public void addListener(ActionListener actionlistener){
		BtnCalcular.addActionListener(actionlistener);
	}
	
	public void AddTotal(String valor){
		TxtTotal.setText(valor);
	}
	
	public boolean Calcular(){
		if(Double.valueOf(txtPaga.getText())-Double.valueOf(TxtTotal.getText())>=0){
			txtCambio.setText(String.valueOf(Double.valueOf(txtPaga.getText())-Double.valueOf(TxtTotal.getText())));
			JOptionPane.showMessageDialog(rootPane,"Operacion Completada");
			this.dispose();
			return true;
		}
		else
		{
			JOptionPane.showMessageDialog(rootPane,"Imposible de calcular");
			return false;
		}
			
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			{
				LblTotal = new JLabel();
				getContentPane().add(LblTotal);
				LblTotal.setText("Total");
				LblTotal.setBounds(23, 30, 84, 31);
			}
			{
				TxtTotal = new JTextField();
				getContentPane().add(TxtTotal);
				TxtTotal.setBounds(104, 35, 135, 21);
			}
			{
				LblPago = new JLabel();
				getContentPane().add(LblPago);
				LblPago.setText("Pago con");
				LblPago.setBounds(23, 86, 76, 14);
			}
			{
				txtPaga = new JTextField();
				getContentPane().add(txtPaga);
				txtPaga.setBounds(104, 83, 135, 21);
			}
			{
				lblCambio = new JLabel();
				getContentPane().add(lblCambio);
				lblCambio.setText("Cambio");
				lblCambio.setBounds(12, 220, 69, 14);
			}
			{
				BtnCalcular = new JButton();
				getContentPane().add(BtnCalcular);
				BtnCalcular.setText("Calcular");
				BtnCalcular.setBounds(12, 246, 81, 21);
			}
			{
				txtCambio = new JTextField();
				getContentPane().add(txtCambio);
				txtCambio.setBounds(93, 213, 135, 21);
			}
			pack();
			this.setSize(399, 312);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}

}
